package com.example.activelifecycletest.service.simple;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.activelifecycletest.R;
/**
 * 简单的服务练习
 * @author zhangding
 * @date 2022年5月10日22:26:17
 */
public class SimpleServiceActivity extends AppCompatActivity implements View.OnClickListener{
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service_simple);
        Button startService = findViewById(R.id.start_service);
        Button stopService = findViewById(R.id.stop_service);
        startService.setOnClickListener(this);
        stopService.setOnClickListener(this);
        /*startService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 启动服务
                Intent startIntent = new Intent(this,MyService.class);
                startService(startIntent);
            }
        });
        stopService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 停止服务
                Intent stopInten = new Intent(this,MyService.class);
                stopService(stopInten);
            }
        });*/
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.start_service:
                // 启动服务
                Intent startIntent = new Intent(this,MyService.class);
                startService(startIntent);
                break;
            case R.id.stop_service:
                // 停止服务
                Intent stopInten = new Intent(this,MyService.class);
                stopService(stopInten);
                break;
            default:
                break;
        }
    }
}
